
import { registerClass } from "../../../cfw/tools/class_decorator";
import { ADName, ResultState, SDKLogicState, SDKState } from "../../SDKDefine";
import BaseAd from "../../core/base/BaseAd";

@registerClass('CocosRewardAd')
export default class CocosRewardAd extends BaseAd {



    hide(): void {

    }

    load(): void {

    }

    onClose(res: any) {
        console.log('NativeTest onClose ', res)
        if (res && res.isEnded || res === undefined) {
            this.callResultCallback(ResultState.YES)
        } else {
            this.callResultCallback(ResultState.NO)
        }
    }


    create() {
        if (!this.ad) {
            this.ad = this.sdk.createRewardedVideoAd(ADName.reward, this.adUnitID, 1);
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
            this.ad.onClose(this.getFunc(this.onClose))
        }
    }

    destroy(): void {
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.offClose(this.getFunc(this.onClose))
            this.ad.destroy();
            this.ad = null;
        }
    }

    show() {
        this.ad.show().then(function () {
        }, function (err: any) {
        });
    }
}
